/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.comandos.visit;

import br.ufc.quixada.adrs.interfaces.Comando;
import br.ufc.quixada.adrs.model.Adrs;
import br.ufc.quixada.adrs.util.Msg;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author ismaily
 */
public class CmdVisitMontaRelatorioQtPassoDois implements Comando {

    public String executa(HttpServletRequest request, HttpServletResponse response) {

        HttpSession session = request.getSession(true);
        ArrayList<Adrs> listaAdrsQT = new ArrayList<Adrs>();
        ArrayList<Adrs> listaAdrsSelecionado = (ArrayList<Adrs>) session.getAttribute("listAdrs");
        ArrayList<Long> idProd = new ArrayList<Long>();
        boolean cb2 = request.getParameter("cb") != null ? true : false;
        if (cb2) {
            String cb[] = request.getParameterValues("cb");
            for (int i = 0; i < cb.length; i++) {
                idProd.add(Long.parseLong(cb[i]));
            }
        } else {
            session.setAttribute("erro", Msg.EMPTY_SELECTION_ERROR_ADRS);
            return "/visit/visit_monta_relatorio_qt_passo_dois.jsp";
        }

        for (Adrs ad : listaAdrsSelecionado) {
            for (Long id : idProd) {
                if (id.equals(ad.getId())) {
                    listaAdrsQT.add(ad);
                    break;
                }
            }
        }
        session.setAttribute("adrsSelecionados", listaAdrsQT);
        return "/visit/visit_monta_relatorio_qt_passo_tres.jsp";
    }
}
